package cn.kgc.sm.service;

import cn.kgc.sm.entity.User;
import cn.kgc.sm.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/7/5
 *
 * isolation：设置事务的隔离级别
 *propagation：事务的传播方式
 */
@Service("userService")
@Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED)
public class UserServiceImpl  implements UserService {
    @Autowired
    private  UserMapper userMapper;

    @Override
    public List<User> findAll() {

        List<User> users = userMapper.selectAll();
        return users;
    }


    //开启事务的支持
    @Override
    //@Transactional
    public Integer delete(Integer id) {
        Integer delete = userMapper.delete(id);
        int a = 1/0;
        return delete;
    }
}
